import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class CrawlerServer {

	
	public static void main (String[]args) {
		
		QueueServer server = QueueServer.getInstance();
		CrawlerClient client = new CrawlerClient();
		client.start();
		
		
		while(true) {
			System.out.println("********Server Crawler Menu*********");
			System.out.println("1. Add URL");
			System.out.println("2. Exit");
			
			System.out.print("Enter Option :");
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			
			int option = 0;
			
			try {
				option = Integer.parseInt(br.readLine());
			}
			catch (NumberFormatException nfe) {
				System.out.println("Error in reading option");
			}
			catch (IOException ioe) {
				System.out.println("IO Error in reading input");
			}
		
			
			switch (option) {
			
			case 1: try {
							System.out.print("Enter URL to add : ");
							String url = br.readLine();
							server.addUrl(url);
					}
					catch (IOException ioe) {
						System.out.println("Error in reading url");
					}
					break;
			
			case 2: System.out.println("\nExixting System");
					LuceneIndexer.getInstance().close();
					System.exit(1);
					break;
			
			default : System.out.println("\nInvalid Option; Please try again");
					  break;
			
			}
			
		}
		
	}
}
